import { get, post, put, del } from '@/utils/request';
import type { ApiResponse } from '@/types/api';

// 部门 SysDept
export interface Dept {
  departmentId?: number;
  departmentName?: string;
  managerId?: number;
  parentId?: number;
  sort?: number;
  createTime?: string;
  updateTime?: string;
}

export function deptList(params?: { departmentName?: string; parentId?: number }) {
  return get<ApiResponse<Dept[]>>('/sysDept/list', { params });
}

export function deptTree() {
  return get<ApiResponse<any[]>>('/sysDept/tree');
}

export function deptGet(id: number) {
  return get<ApiResponse<Dept>>(`/sysDept/${id}`);
}

export function deptAdd(body: Dept) {
  return post<ApiResponse<string>>('/sysDept/add', body);
}

export function deptUpdate(body: Dept) {
  return put<ApiResponse<string>>('/sysDept/update', body);
}

export function deptDelete(ids: number[]) {
  const params = new URLSearchParams();
  params.set('ids', ids.join(','));
  return del<ApiResponse<string>>(`/sysDept/delete?${params.toString()}`);
}

// 职位/职务 SysPost
export interface PostEntity {
  positionId?: number;
  positionName?: string;
  positionLevel?: string;
  sort?: number;
  remark?: string;
  deletedFlag?: boolean;
  createTime?: string;
  updateTime?: string;
}

export function postList(params?: { positionName?: string; positionLevel?: string; pageNo?: number; pageSize?: number }) {
  return get<ApiResponse<any>>('/sysPost/list', { params });
}

export function postGet(id: number) {
  return get<ApiResponse<PostEntity>>(`/sysPost/${id}`);
}

export function postAdd(body: PostEntity) {
  return post<ApiResponse<string>>('/sysPost/add', body);
}

export function postUpdate(body: PostEntity) {
  return put<ApiResponse<string>>('/sysPost/update', body);
}

export function postDelete(ids: number[]) {
  const params = new URLSearchParams();
  params.set('ids', ids.join(','));
  return del<ApiResponse<string>>(`/sysPost/delete?${params.toString()}`);
}